// c_sdk.cpp
#include "c_sdk.h"
#include "sdk.h"
#include <cstring>
#include <memory>

extern "C" {
    
SdkHandle create_sdk() {
    try {
        return new Sdk();
    } catch (...) {
        return nullptr;
    }
}

void destroy_sdk(SdkHandle handle) {
    delete static_cast<Sdk*>(handle);
}

int initialize_sdk(SdkHandle handle, const char* config) {
    if (!handle || !config) return -1;
    static_cast<Sdk*>(handle)->initialize(config);
    return 0;
}

int process_data(SdkHandle handle, int data) {
    if (!handle) return -1;
    return static_cast<Sdk*>(handle)->processData(data) ? 0 : -1;
}

const char* get_result(SdkHandle handle) {
    if (!handle) return nullptr;
    // 注意：需要保证返回字符串的生命周期
    static thread_local std::string result;
    result = static_cast<Sdk*>(handle)->getResult();
    return result.c_str();
}

}